package com.mypack.crm.controller.follow;

import com.github.pagehelper.PageInfo;
import com.mypack.crm.constants.EnumDeleteFlag;
import com.mypack.crm.constants.EnumResponse;
import com.mypack.crm.dto.customer.CustomerDTO;
import com.mypack.crm.dto.follow.FollowRecordDTO;
import com.mypack.crm.dto.follow.FollowRecordSearchDTO;
import com.mypack.crm.service.follow.FollowService;
import com.mypack.crm.utils.Result;
import com.mypack.crm.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/follow/record")
public class FollowRecordController {

    @Autowired
    private FollowService followService;


    @RequestMapping("/list")
    public Result list(@RequestBody FollowRecordSearchDTO searchDTO) {

        List<FollowRecordDTO> list = followService.list(searchDTO, true);

        return ResultUtils.success(new PageInfo<>(list));
    }

    @RequestMapping("/add")
    public Result add(@RequestBody FollowRecordDTO followRecordDTO) {

        followService.add(followRecordDTO);

        return ResultUtils.success();
    }


    @RequestMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Integer id) {

        if (id == null) {
            return ResultUtils.fail(EnumResponse.INVALID_PARAM);
        }

        followService.delete(id);

        return ResultUtils.success();
    }

}
